package com._CPA_.controller;

import com._CPA_.pojo.Result;
import com._CPA_.utils.MinIoUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@Slf4j
@RestController
@CrossOrigin
@RequestMapping(value = "/upload")
@ApiModel(value = "文件上传")
public class UploadController {
    @Resource
    private MinIoUtils minIoUtils;
    // 存储桶名称
    private static final String MINIO_BUCKET = "cpa-images";

    //上传图片
    @PostMapping("/img")
    @ApiOperation(value = "用户头像上传")
    public Result upload(String username, Integer age, MultipartFile image) throws Exception {
        try {
            return Result.success(minIoUtils.upload(image, MINIO_BUCKET, null));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }}






